angular.module('robot', [])

    .config(function RobotRoutes($stateProvider) {
        $stateProvider

            .state('robotList', {//路由名称
                parent: 'admin',
                url: '/robotList?{robotNumber:string}&{groupId:string}',
                params: {
                    page: { value: 1, squash: true },//初始化url中的参数，不需要可以不写
                    size: { value: 10, squash: true }
                },
                views: {
                    'main@admin': {
                        templateUrl: 'admin/robot/list.html',//html地址
                        controller: 'RobotController as vm',//控制器和他的别名
                        resolve: {
                            initialList: function(Robot, $stateParams) {//从后台预加载的数据,Demo-注入的service
                                return Robot.search({
                                    robotNumber: $stateParams.robotNumber,
                                    groupId: $stateParams.groupId,
                                    pageInfo: {
                                        pageSize: $stateParams.size,
                                        pageNumber: $stateParams.page
                                    }
                                })
                            }
                        }
                    }
                }
            })
            .state('robotChooseGroup',{
                url: '/robotChooseGroup?{robotId:string}',
                params: {
                    robotId: null
                },
                controller: 'RobotChooseGroupController as vm',//控制器和他的别名
                templateUrl: 'admin/robot/robotChooseGroup.html',
                resolve: {
                    params: function($stateParams){
                        return $stateParams.robotId;
                    },
                    validAdmin: function ($state,store) {
                        if(_.isNull(store.get('currentAdmin'))){
                            $state.go('session.signin')
                        }
                    }
                }
            })
    })

    .service('Robot', RobotModel)//声明

    .controller('RobotController', RobotController)
    .controller('RobotChooseGroupController', RobotChooseGroupController)


    //弹出框组件
    .controller('ModalInstanceCtrl', function ($scope, $uibModalInstance) {
        $scope.ok = function () {
            $uibModalInstance.close('ok');
        };
        $scope.cancel = function () {
            $uibModalInstance.close('cancel');
        };
    })

    //弹出框组件
    .controller('robotTipsCtrl', function ($scope, $uibModalInstance) {
        $scope.resultMsg = $scope.data.msg;
        $scope.ok = function () {
            $uibModalInstance.close('ok');
        };
    })
